using System.ComponentModel;
using System.Xml.Serialization;
using uTILLIty.Rave.Contract.StorageAdapter;

namespace uTILLIty.Rave.Contract.Configuration
{
	/// <summary>
	/// Holds confiuration information about a directory/path entry
	/// </summary>
	/// <remarks>
	/// The provider is passed this directory in a <see cref="DirectoryContext"/>
	/// context-object
	/// </remarks>
	public class Directory
	{
		/// <summary>
		/// the Default constructor used by the XML serializer
		/// </summary>
		public Directory()
		{
			SkipProcessingIfDirectoryExists = true;
		}

		/// <summary>
		/// Creates a minimally configured directory object
		/// </summary>
		/// <param name="name">the directory's name</param>
		public Directory(string name)
			: this()
		{
			Name = name;
		}

		/// <summary>
		/// The name of the directory in the store
		/// </summary>
		/// <remarks>
		/// The adapter's <see cref="IStorageAdapter.ValidateDirectory"/> implementation should
		/// insure that this name is valid in the underlying store
		/// </remarks>
		[XmlElement(IsNullable = false)]
		public string Name { get; set; }

		/// <summary>
		/// Wether to remove all other ACL entries not specified (semantically) in the provided
		/// list of <see cref="SecurityEntries"/>
		/// </summary>
		[DefaultValue(false), XmlAttribute("removeAllOtherSecurityEntries")]
		public bool RemoveAllOtherSecurityEntries { get; set; }

		/// <summary>
		/// Wether to turn ACL inheritance off
		/// </summary>
		[DefaultValue(false), XmlAttribute("removeSecurityEntriesInheritance")]
		public bool RemoveSecurityEntriesInheritance { get; set; }

		/// <summary>
		/// Wether to skip processing the ACL entries, if the directory already exists
		/// </summary>
		/// <remarks>
		/// speeds up processing large trees (with usually unchanging ACLs), if set to True
		/// </remarks>
		[DefaultValue(true), XmlAttribute("skipProcessingIfDirectoryExists")]
		public bool SkipProcessingIfDirectoryExists { get; set; }

		/// <summary>
		/// A list of <see cref="SecurityEntry">ACL-entries</see> to add to the ACL
		/// </summary>
		[XmlArrayItem(typeof(SecurityEntry))]
#pragma warning disable 612,618
		[XmlArrayItem(typeof(UserSecurityEntry))]
		[XmlArrayItem(typeof(GroupSecurityEntry))]
#pragma warning restore 612,618
		public SecurityEntry[] SecurityEntries { get; set; }

		/// <summary>
		/// A list of sub-<see cref="Directory">directories</see> to process/create
		/// beneath this instance
		/// </summary>
		public Directory[] SubDirectories { get; set; }

		/// <summary>
		/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
		/// </summary>
		/// <returns>
		/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
		/// </returns>
		/// <filterpriority>2</filterpriority>
		public override string ToString()
		{
			return string.Format("{0}", Name);
		}
	}
}